home *** CD-ROM | disk | FTP | other *** search
- Return-Path: @UUNET.UU.NET:sun!pyramid!prls!gordon@seismo.CSS.GOV
- Message-Id: <8710010021.AA10975@pyramid.UUCP>
- Date: Wed, 30 Sep 87 16:51:45 pdt
- From: Gordon Vickers <sun!prls!gordon@seismo.CSS.GOV>
- To: sources@seismo.CSS.GOV
- Subject: soundslike; LOOK(1) like program with soundex
-
- This is another aid to those who can't spell . It is similar to the basic
- function of LOOK(1) but uses what I believe is the "soundex" algorithm.
- The code is VERY tame so I would expect to to port easily though I am no
- expert on such matters. Comments, suggestions, etc are welcomed.
-
-
- Gordon P. Vickers, (408) 991-5370, =======================
- Signetics Corp. || Ultrix-32 ver 1.2 ||
- PO Box 3409 M/S 69 || VAX 11/750 ||
- Sunnyvale, California, USA 94086 =======================
- {pyramid, philabs}!prls!gordon
-
- [ I turned the formatted manpage into an unformatted one, along with
- light editing, and wrote a Makefile. Feel free to take the latter
- as a prototype makefile for submissions... Also, I don't know if
- this is true "soundex" or not -- and I don't care -- it works nicely.
- --r$ ]
-
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then unpack
- # it by saving it into a file and typing "sh file". To overwrite existing
- # files, type "sh file -c". You can also feed this as standard input via
- # unshar, or by typing "sh <file", e.g.. If this archive is complete, you
- # will see the following message at the end:
- # "End of shell archive."
- # Contents: Makefile soundslike.1 soundslike.c
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- if test -f 'Makefile' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'Makefile'\"
- else
- echo shar: Extracting \"'Makefile'\" \(178 characters\)
- sed "s/^X//" >'Makefile' <<'END_OF_FILE'
- X# Makefile for soundslike.
- XCFLAGS = -O
- Xp = soundslike
- Xall: $p $p.1
- Xinstall: all
- X @echo install $p and $p.1 according to local convention.
- X
- X$p: $p.c
- X $(CC) $(CFLAGS) -o $p $p.c
- END_OF_FILE
- if test 178 -ne `wc -c <'Makefile'`; then
- echo shar: \"'Makefile'\" unpacked with wrong size!
- fi
- # end of 'Makefile'
- fi
- if test -f 'soundslike.1' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'soundslike.1'\"
- else
- echo shar: Extracting \"'soundslike.1'\" \(928 characters\)
- sed "s/^X//" >'soundslike.1' <<'END_OF_FILE'
- X.TH SOUNDSLIKE 1 LOCAL
- X.SH NAME
- Xsoundslike \- spell word based on what it sounds like
- X.SH SYNOPSIS
- X.B soundslike
- Xword
- X.br
- X.B soundslike
- X-filename word
- X.br
- X.B soundslike
- Xword -filename
- X.SH DESCRIPTION
- X.I Soundslike
- Xuses an implementation of the soundex algorithm.
- XType the word in question as best as you can,
- Xand the program will search a database for similar-sounding words.
- XThe default database is normally
- X.I /usr/dict/words
- Xbut the user may specify any other file.
- X.PP
- XRegardless of which file is specified as the database, only the
- Xfirst word of each line is tested against the users' word.
- X.PP
- XFor example,
- X.RS
- Xsoundslike butiful
- X.RE
- Xwill produce:
- X.RS
- Xbeautiful
- Xbiddable
- Xbotfly
- X.RE
- Xand
- X.RS
- Xsoundslike nessaccary
- X.RE
- Xproduces:
- X.RS
- Xnecessary
- X.RE
- X.SH RESTRICTIONS
- XYou must be able to at least get the first letter correct.
- X.SH AUTHOR
- X.nf
- XGordon P. Vickers
- XSignetics Corp. , Sunnyvale, Ca.
- X{pyramid, philabs}!prls!gordon
- X.fi
- END_OF_FILE
- if test 928 -ne `wc -c <'soundslike.1'`; then
- echo shar: \"'soundslike.1'\" unpacked with wrong size!
- fi
- # end of 'soundslike.1'
- fi
- if test -f 'soundslike.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'soundslike.c'\"
- else
- echo shar: Extracting \"'soundslike.c'\" \(3557 characters\)
- sed "s/^X//" >'soundslike.c' <<'END_OF_FILE'
- X#include <stdio.h>
- X#include <strings.h>
- X
- X/*******************************************************
- X * Soundex (like) filter. Default database is DEFDB *
- X * or user specifies with "-filename" *
- X * syntex: soundex word *
- X * soundex -database word *
- X * soundex word -database *
- X ******************************************************/
- X
- X#define DEFDB "/usr/dict/words" /* default database */
- X
- Xmain(argc,argv)
- X int argc;
- X char **argv;
- X{
- X void mkcode(), syntex();
- X int i;
- X char c;
- X char dbname[BUFSIZ], word[BUFSIZ], s[BUFSIZ];
- X char dbword[BUFSIZ], dbcode[BUFSIZ];
- X
- X sprintf(dbname,"%s",DEFDB);
- X if(argc == 1)
- X syntex(argv[0]); /* print syntex help then exit */
- X
- X
- X for(i = 1; argv[i] != NULL; i++) { /* process argument line */
- X if( argv[i][0] == '-')
- X sprintf(dbname,"%s",argv[i]);
- X else
- X sprintf(word,"%s",argv[i]);
- X }
- X
- X if( !strlen(word) )
- X syntex(argv[0]);
- X
- X if ( freopen(dbname,"r",stdin) == NULL ) {
- X perror(dbname);
- X exit(0);
- X }
- X
- X /* Sanity checks done. Now, down to buisness */
- X
- X c = word[0];
- X mkcode(word);
- X
- X while( (gets(dbword) ) != NULL ) {
- X if( c < dbword[0] ) /* assumes database is in alphabetical order */
- X break;
- X else if (c > dbword[0])
- X continue;
- X else {
- X sscanf(dbword,"%s%*s",dbcode); /* isolate only first word */
- X sprintf(dbword,"%s",dbcode); /* truncate dbword to one word */
- X mkcode(dbcode); /* convert to code */
- X if( !strcmp(dbcode,word) ) /* check for exact code match */
- X printf("%s\n",dbword);
- X }
- X }
- X}
- X
- X/********************************* MKCODE() ****************************/
- Xvoid mkcode(codeword)
- X char *codeword;
- X{
- X int i, j = 0;
- X int l;
- X
- X l = strlen(codeword);
- X if(l <= 1){ /* this should probably return some snide remark */
- X codeword[l] = '\0';
- X return;
- X }
- X
- X for(i = 1; codeword[i] != NULL; i++) {
- X if(codeword[i] == codeword[i - 1])
- X continue;
- X switch (codeword[i]) {
- X case 'b':
- X case 'f':
- X case 'p':
- X case 'v': codeword[j] = '1';
- X j++;
- X break;
- X
- X case 'c':
- X case 'g':
- X case 'j':
- X case 'k':
- X case 'q':
- X case 's':
- X case 'x':
- X case 'z': codeword[j] = '2';
- X j++;
- X break;
- X
- X case 'd':
- X case 't': codeword[j] = '3';
- X j++;
- X break;
- X
- X case 'l': codeword[j] = '4';
- X j++;
- X break;
- X
- X case 'm':
- X case 'n': codeword[j] = '5';
- X j++;
- X break;
- X
- X case 'r': codeword[j] = '6';
- X j++;
- X break;
- X
- X default : break;
- X }
- X }
- X codeword[j] = '\0';
- X while( strlen(codeword) < 3 ) /* pad with zeroes til minimum length */
- X strcat(codeword,"0");
- X
- X
- X}
- X
- X/******************************* SYNTEX() **************************/
- Xvoid syntex(name)
- X char *name;
- X{
- X printf("syntex: %s word\n",name);
- X printf(" or %s -database word\n",name);
- X printf(" or %s word -database\n",name);
- X exit(0);
- X}
- END_OF_FILE
- if test 3557 -ne `wc -c <'soundslike.c'`; then
- echo shar: \"'soundslike.c'\" unpacked with wrong size!
- fi
- # end of 'soundslike.c'
- fi
- echo shar: End of shell archive.
- exit 0
-